var array = new Array(10).fill(undefined).map((item, index) => {
  return index
})

function sort_  (arr) {
  arr.sort(() => {
    return Math.floor(Math.random() * 2 + (-1))
  })
  return arr
}


function mini (array) {
  const miniItem = Math.min(...array)
  const minIndex = array.findIndex(item => item === miniItem)
  return {miniItem, minIndex}
}
function format(arr) {
  let _arr =sort_(arr)
  let length = _arr.length
  let result = []
  for (let x = 0; x < length; x++) {
    const {minIndex} = mini(_arr)
    const item = _arr.splice(minIndex, 1)
    result = [...result, ...item]
  }
  
  return result
}

console.log(format(array))